﻿using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Controls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TrafficAccessibilityIndex
{
    public partial class GravityModelForm : Form
    {
        private AxMapControl axMapControl;
        private ILayer _junctionLayer = null;

        public ILayer JunctionLayer
        {
            get { return _junctionLayer; }
        }

        private ILayer _poiLayer1 = null;

        public ILayer POILayer1
        {
            get { return _poiLayer1; }
        }

        private ILayer _featureLayer = null;

        public ILayer FeatureLayer
        {
            get { return _featureLayer; }
        }


        public GravityModelForm()
        {
            InitializeComponent();
        }
        public GravityModelForm(AxMapControl axMapControl)
            : this()
        {
            this.axMapControl = axMapControl;
        }

        private ILayer GetLayerByName(string layerName)
        {
            int layerCount = this.axMapControl.LayerCount;
            for (int i = 0; i < layerCount; ++i)
            {
                ILayer result = this.axMapControl.get_Layer(i);
                string name = result.Name;
                if (name == layerName)
                {
                    return result;
                }
            }
            return null;
        }

        private void buttonOK_Click(object sender, EventArgs e)
        {

         
            string layerName = this.comboBoxPOI.SelectedItem.ToString();
            this._poiLayer1 = GetLayerByName(layerName);

            layerName = this.comboBox1.SelectedItem.ToString();
            this._junctionLayer = GetLayerByName(layerName);

            layerName = this.comboBoxFeature.SelectedItem.ToString();
            this._featureLayer = GetLayerByName(layerName);

            //if (this.comboBoxSpeedFiled.SelectedIndex != -1)
            //{
            //    _speedFiledName = this.comboBoxSpeedFiled.SelectedItem.ToString();
            //}

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Dispose();
        }

        private void buttonCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.Dispose();
        }

        private void GravityModelForm_Load(object sender, EventArgs e)
        {
            int layerCount = this.axMapControl.LayerCount;
            for (int i = 0; i < layerCount; ++i)
            {
                string name = this.axMapControl.get_Layer(i).Name;
                //this.comboBoxLayerRoad.Items.Add(name);

                this.comboBoxPOI.Items.Add(name);

                this.comboBox1.Items.Add(name);

                this.comboBoxFeature.Items.Add(name);
            }
        }

    }
}
